import logging

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

logger = logging.getLogger(__name__)

class TextInputWindow(QDialog):
    def __init__(self, title, message, placeholder='', default=''):
        super().__init__()

        self.return_data = None

        layout = QVBoxLayout()
        self.setLayout(layout)

        self.message_label = QLabel(message)
        self.layout().addWidget(self.message_label)
        self.text_edit = QLineEdit(default)
        self.text_edit.setPlaceholderText(placeholder)
        self.layout().addWidget(self.text_edit)

        options_layout = QHBoxLayout()
        self.cancel_button = QPushButton('Cancel')
        self.cancel_button.clicked.connect(self.on_cancel)
        options_layout.addWidget(self.cancel_button)
        self.confirm_button = QPushButton('Confirm')
        self.confirm_button.clicked.connect(self.on_confirm)
        options_layout.addWidget(self.confirm_button)
        self.layout().addLayout(options_layout)

    def on_confirm(self):
        self.return_data = self.text_edit.text()
        self.accept()

    def on_cancel(self):
        self.accept()

def ask_text(title, message, placeholder='', default=''):
    window = TextInputWindow(title, message, placeholder, default)
    window.exec_()
    return window.return_data
